// 
// CantripColorCell.m 
// Color well cell class
// 
// Created by James Callender on Sat Jul 19 2003. 
// Copyright (c) 2003 James Callender. All rights reserved. 
// 

#import "CantripColorCell.h" 

@implementation CantripColorCell 

// Originally written by John Harte
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView*) 
controlView
{ 
    NSRect square = cellFrame;

    // Allow for empty swatches
    if (![self objectValue]) return;
    
    // use the smallest size to sqare off the box & center the box 
    if (square.size.height < square.size.width) 
    { 
        square.size.width = square.size.height; 
        square.origin.x = square.origin.x + roundf((cellFrame.size.width - square.size.width) / 2.0); 
    } 
    else 
    { 
        square.size.height = square.size.width; 
        square.origin.y = square.origin.y + roundf((cellFrame.size.height - square.size.height) / 2.0); 
    } 

    square = NSInsetRect (square, 0.5, 0.5);
    [[NSColor blackColor] set]; 
    [NSBezierPath strokeRect: square]; 

    [(NSColor*) [self objectValue] set]; 
    [NSBezierPath fillRect: NSInsetRect (square, 2.0, 2.0)]; 
    // Should we use the built-in method?
    //[[self objectValue] drawSwatchInRect:NSInsetRect(square, 2.0, 2.0)];
}

@end 

